package com.ezandroid.library.network.http.params;

import android.text.TextUtils;

import java.io.File;
import java.util.HashMap;

/**
 * MIME type.
 *
 * @author markmjw
 * @date 2014-04-25
 */
public class MIMEType {

    private final static HashMap<String, String> types = new HashMap<>();

    public static String getContentType(File file) {
        if (null != file && file.exists()) {
            String suffix = exportSuffix(file.getPath());
            if (types.containsKey(suffix)) {
                return types.get(suffix);
            }
        }

        return "";
    }

    public static String getContentType(String fileName) {
        if (TextUtils.isEmpty(fileName)) {
            String suffix = exportSuffix(fileName);
            if (types.containsKey(suffix)) {
                return types.get(suffix);
            }
        }

        return "";
    }

    private static String exportSuffix(String path) {
        return path.substring(path.lastIndexOf(".") + 1);
    }

    static {
        types.put("123", "application/vnd.lotus-1-2-3");
        types.put("3gp", "video/3gpp");
        types.put("aab", "application/x-authoware-bin");
        types.put("aam", "application/x-authoware-map");
        types.put("aas", "application/x-authoware-seg");
        types.put("aia", "pplication/postscript");
        types.put("aif", "audio/x-aiff");
        types.put("aifc", "audio/x-aiff");
        types.put("aiff", "audio/x-aiff");
        types.put("als", "audio/X-Alpha5");
        types.put("amc", "application/x-mpeg");
        types.put("ani", "application/octet-stream");
        types.put("asc", "text/plain");
        types.put("asd", "application/astound");
        types.put("asf", "video/x-ms-asf");
        types.put("asn", "application/astound");
        types.put("asp", "application/x-asap");
        types.put("asx", "video/x-ms-asf");
        types.put("au", "audio/basic");
        types.put("avb", "application/octet-stream");
        types.put("avi", "video/x-msvideo");
        types.put("awb", "audio/amr-wb");
        types.put("bcpio", "application/x-bcpio");
        types.put("bin", "application/octet-stream");
        types.put("bld", "application/bld");
        types.put("bld2", "application/bld2");
        types.put("bmp", "application/x-MS-bmp");
        types.put("bpk", "application/octet-stream");
        types.put("bz2", "application/x-bzip2");
        types.put("cal", "image/x-cals");
        types.put("ccn", "application/x-cnc");
        types.put("cco", "application/x-cocoa");
        types.put("cdf", "application/x-netcdf");
        types.put("cer", "application/x-x509-ca-cert");
        types.put("cg", "imagnus-internal/cgi");
        types.put("chat", "application/x-chat");
        types.put("class", "application/octet-stream");
        types.put("clp", "application/x-msclip");
        types.put("cmx", "application/x-cmx");
        types.put("co", "application/x-cult3d-object");
        types.put("cod", "image/cis-cod");
        types.put("cpio", "application/x-cpio");
        types.put("cpt", "application/mac-compactpro");
        types.put("crd", "application/x-mscardfile");
        types.put("csh", "application/x-csh");
        types.put("csm", "chemical/x-csml");
        types.put("csml", "chemical/x-csml");
        types.put("css", "text/css");
        types.put("cur", "application/octet-stream");
        types.put("dcm", "x-lml/x-evm");
        types.put("dcr", "application/x-director");
        types.put("dcx", "image/x-dcx");
        types.put("dhtml", "text/html");
        types.put("dir", "application/x-director");
        types.put("dll", "application/octet-stream");
        types.put("dmg", "application/octet-stream");
        types.put("dms", "application/octet-stream");
        types.put("doc", "application/msword");
        types.put("dot", "application/x-dot");
        types.put("dvi", "application/x-dvi");
        types.put("dwf", "drawing/x-dwf");
        types.put("dwg", "application/x-autocad");
        types.put("dxf", "application/x-autocad");
        types.put("dxr", "application/x-director");
        types.put("ebk", "application/x-expandedbook");
        types.put("emb", "chemical/x-embl-dl-nucleotide");
        types.put("embl", "chemical/x-embl-dl-nucleotide");
        types.put("eps", "application/postscript");
        types.put("eri", "image/x-eri");
        types.put("es", "audio/echospeech");
        types.put("esl", "audio/echospeech");
        types.put("etc", "application/x-earthtime");
        types.put("etx", "text/x-setext");
        types.put("evm", "x-lml/x-evm");
        types.put("evy", "application/x-envoy");
        types.put("exe", "application/octet-stream");
        types.put("fh4", "image/x-freehand");
        types.put("fh5", "image/x-freehand");
        types.put("fhc", "image/x-freehand");
        types.put("fif", "image/fif");
        types.put("fm", "application/x-maker");
        types.put("fpx", "image/x-fpx");
        types.put("fvi", "video/isivideo");
        types.put("gau", "chemical/x-gaussian-input");
        types.put("gca", "application/x-gca-compressed");
        types.put("gdb", "x-lml/x-gdb");
        types.put("gif", "image/gif");
        types.put("gps", "application/x-gps");
        types.put("gtar", "application/x-gtar");
        types.put("gz", "application/x-gzip");
        types.put("hdf", "application/x-hdf");
        types.put("hdm", "text/x-hdml");
        types.put("hdml", "text/x-hdml");
        types.put("hlp", "application/winhlp");
        types.put("hqx", "application/mac-binhex40");
        types.put("htm", "text/html");
        types.put("html", "text/html");
        types.put("hts", "text/html");
        types.put("ice", "x-conference/x-cooltalk");
        types.put("ico", "application/octet-stream");
        types.put("ief", "image/ief");
        types.put("ifm", "image/gif");
        types.put("ifs", "image/ifs");
        types.put("imy", "audio/melody");
        types.put("ins", "application/x-NET-Install");
        types.put("ips", "application/x-ipscript");
        types.put("ipx", "application/x-ipix");
        types.put("it", "audio/x-mod");
        types.put("itz", "audio/x-mod");
        types.put("ivr", "i-world/i-vrml");
        types.put("j2k", "image/j2k");
        types.put("jad", "text/vnd.sun.j2me.app-descriptor");
        types.put("jam", "application/x-jam");
        types.put("jar", "application/java-archive");
        types.put("jnlp", "application/x-java-jnlp-file");
        types.put("jpe", "image/jpeg");
        types.put("jpeg", "image/jpeg");
        types.put("jpg", "image/jpeg");
        types.put("jpz", "image/jpeg");
        types.put("js", "application/x-javascript");
        types.put("jwc", "application/jwc");
        types.put("kjx", "application/x-kjx");
        types.put("lak", "x-lml/x-lak");
        types.put("latex", "application/x-latex");
        types.put("lcc", "application/fastman");
        types.put("lcl", "application/x-digitalloca");
        types.put("lcr", "application/x-digitalloca");
        types.put("lgh", "application/lgh");
        types.put("lha", "application/octet-stream");
        types.put("lml", "x-lml/x-lml");
        types.put("lmlpack", "x-lml/x-lmlpack");
        types.put("lsf", "video/x-ms-asf");
        types.put("lsx", "video/x-ms-asf");
        types.put("lzh", "application/x-lzh");
        types.put("m13", "application/x-msmediaview");
        types.put("m14", "application/x-msmediaview");
        types.put("m15", "audio/x-mod");
        types.put("m3u", "audio/x-mpegurl");
        types.put("m3url", "audio/x-mpegurl");
        types.put("ma1", "audio/ma1");
        types.put("ma2", "audio/ma2");
        types.put("ma3", "audio/ma3");
        types.put("ma5", "audio/ma5");
        types.put("man", "application/x-troff-man");
        types.put("map", "magnus-internal/imagemap");
        types.put("mbd", "application/mbedlet");
        types.put("mct", "application/x-mascot");
        types.put("mdb", "application/x-msaccess");
        types.put("mdz", "audio/x-mod");
        types.put("me", "application/x-troff-me");
        types.put("mel", "text/x-vmel");
        types.put("mi", "application/x-mif");
        types.put("mid", "audio/midi");
        types.put("midi", "audio/midi");
        types.put("mif", "application/x-mif");
        types.put("mil", "image/x-cals");
        types.put("mio", "audio/x-mio");
        types.put("mmf", "application/x-skt-lbs");
        types.put("mng", "video/x-mng");
        types.put("mny", "application/x-msmoney");
        types.put("moc", "application/x-mocha");
        types.put("mocha", "application/x-mocha");
        types.put("mod", "audio/x-mod");
        types.put("mof", "application/x-yumekara");
        types.put("mol", "chemical/x-mdl-molfile");
        types.put("mop", "chemical/x-mopac-input");
        types.put("mov", "video/quicktime");
        types.put("mov", "ievideo/x-sgi-movie");
        types.put("mp2", "audio/x-mpeg");
        types.put("mp3", "audio/x-mpeg");
        types.put("mp4", "video/mp4");
        types.put("mpc", "application/vnd.mpohun.certificate");
        types.put("mpe", "video/mpeg");
        types.put("mpeg", "video/mpeg");
        types.put("mpg", "video/mpeg");
        types.put("mpg4", "video/mp4");
        types.put("mpga", "audio/mpeg");
        types.put("mpn", "application/vnd.mophun.application");
        types.put("mpp", "application/vnd.ms-project");
        types.put("mps", "application/x-mapserver");
        types.put("mrl", "text/x-mrml");
        types.put("mrm", "application/x-mrm");
        types.put("ms", "application/x-troff-ms");
        types.put("mts", "application/metastream");
        types.put("mtx", "application/metastream");
        types.put("mtz", "application/metastream");
        types.put("mzv", "application/metastream");
        types.put("nar", "application/zip");
        types.put("nbmp", "image/nbmp");
        types.put("nc", "application/x-netcdf");
        types.put("ndb", "x-lml/x-ndb");
        types.put("ndwn", "application/ndwn");
        types.put("nif", "application/x-nif");
        types.put("nmz", "application/x-scream");
        types.put("nokia-op-logo", "image/vnd.nok-oplogo-color");
        types.put("npx", "application/x-netfpx");
        types.put("nsnd", "audio/nsnd");
        types.put("nva", "application/x-neva1");
        types.put("oda", "application/oda");
        types.put("oom", "application/x-AtlasMate-Plugin");
        types.put("pac", "audio/x-pac");
        types.put("pae", "audio/x-epac");
        types.put("pan", "application/x-pan");
        types.put("pbm", "image/x-portable-bitmap");
        types.put("pcx", "image/x-pcx");
        types.put("pda", "image/x-pda");
        types.put("pdb", "chemical/x-pdb");
        types.put("pdf", "application/pdf");
        types.put("pfr", "application/font-tdpfr");
        types.put("pgm", "image/x-portable-graymap");
        types.put("pict", "image/x-pict");
        types.put("pm", "application/x-perl");
        types.put("pmd", "application/x-pmd");
        types.put("png", "image/png");
        types.put("pnm", "image/x-portable-anymap");
        types.put("pnz", "image/png");
        types.put("pot", "application/vnd.ms-powerpoint");
        types.put("ppm", "image/x-portable-pixmap");
        types.put("pps", "application/vnd.ms-powerpoint");
        types.put("ppt", "application/vnd.ms-powerpoint");
        types.put("pqf", "application/x-cprplayer");
        types.put("pqi", "application/cprplayer");
        types.put("prc", "application/x-prc");
        types.put("pro", "xyapplication/x-ns-httpProxy-autoconfig");
        types.put("ps", "application/postscript");
        types.put("ptlk", "application/listenup");
        types.put("pub", "application/x-mspublisher");
        types.put("pvx", "video/x-pv-pvx");
        types.put("qcp", "audio/vnd.qcelp");
        types.put("qt", "video/quicktime");
        types.put("qti", "image/x-quicktime");
        types.put("qtif", "image/x-quicktime");
        types.put("r3t", "text/vnd.rn-realtext3d");
        types.put("ra", "audio/x-pn-realaudio");
        types.put("ram", "audio/x-pn-realaudio");
        types.put("rar", "application/x-rar-compressed");
        types.put("ras", "image/x-cmu-raster");
        types.put("rdf", "application/rdf+xml");
        types.put("rf", "image/vnd.rn-realflash");
        types.put("rgb", "image/x-rgb");
        types.put("rlf", "application/x-richlink");
        types.put("rm", "audio/x-pn-realaudio");
        types.put("rmf", "audio/x-rmf");
        types.put("rmm", "audio/x-pn-realaudio");
        types.put("rmvb", "audio/x-pn-realaudio");
        types.put("rnx", "application/vnd.rn-realplayer");
        types.put("roff", "application/x-troff");
        types.put("rp", "image/vnd.rn-realpix");
        types.put("rpm", "audio/x-pn-realaudio-plugin");
        types.put("rt", "text/vnd.rn-realtext");
        types.put("rte", "x-lml/x-gps");
        types.put("rtf", "application/rtf");
        types.put("rtg", "application/metastream");
        types.put("rtx", "text/richtext");
        types.put("rv", "video/vnd.rn-realvideo");
        types.put("rwc", "application/x-rogerwilco");
        types.put("s3m", "audio/x-mod");
        types.put("s3z", "audio/x-mod");
        types.put("sca", "application/x-supercard");
        types.put("scd", "application/x-msschedule");
        types.put("sdf", "application/e-score");
        types.put("sea", "application/x-stuffit");
        types.put("sgm", "text/x-sgml");
        types.put("sgml", "text/x-sgml");
        types.put("sh", "application/x-sh");
        types.put("shar", "application/x-shar");
        types.put("shtml", "magnus-internal/parsed-html");
        types.put("shw", "application/presentations");
        types.put("si6", "image/si6");
        types.put("si7", "image/vnd.stiwap.sis");
        types.put("si9", "image/vnd.lgtwap.sis");
        types.put("sis", "application/vnd.symbian.install");
        types.put("sit", "application/x-stuffit");
        types.put("skd", "application/x-Koan");
        types.put("skm", "application/x-Koan");
        types.put("skp", "application/x-Koan");
        types.put("skt", "application/x-Koan");
        types.put("slc", "application/x-salsa");
        types.put("smd", "audio/x-smd");
        types.put("smi", "application/smil");
        types.put("smil", "application/smil");
        types.put("smp", "application/studiom");
        types.put("smz", "audio/x-smd");
        types.put("snd", "audio/basic");
        types.put("spc", "text/x-speech");
        types.put("spl", "application/futuresplash");
        types.put("spr", "application/x-sprite");
        types.put("sprite", "application/x-sprite");
        types.put("spt", "application/x-spt");
        types.put("src", "application/x-wais-source");
        types.put("stk", "application/hyperstudio");
        types.put("stm", "audio/x-mod");
        types.put("sv4cpio", "application/x-sv4cpio");
        types.put("sv4crc", "application/x-sv4crc");
        types.put("svf", "image/vnd");
        types.put("svg", "image/svg-xml");
        types.put("svh", "image/svh");
        types.put("svr", "x-world/x-svr");
        types.put("swf", "application/x-shockwave-flash");
        types.put("swfl", "application/x-shockwave-flash");
        types.put("t", "application/x-troff");
        types.put("tad", "application/octet-stream");
        types.put("talk", "text/x-speech");
        types.put("tar", "application/x-tar");
        types.put("taz", "application/x-tar");
        types.put("tbp", "application/x-timbuktu");
        types.put("tbt", "application/x-timbuktu");
        types.put("tcl", "application/x-tcl");
        types.put("tex", "application/x-tex");
        types.put("texi", "application/x-texinfo");
        types.put("texinfo", "application/x-texinfo");
        types.put("tgz", "application/x-tar");
        types.put("thm", "application/vnd.eri.thm");
        types.put("tif", "image/tiff");
        types.put("tiff", "image/tiff");
        types.put("tki", "application/x-tkined");
        types.put("tkined", "application/x-tkined");
        types.put("toc", "application/toc");
        types.put("toy", "image/toy");
        types.put("tr", "application/x-troff");
        types.put("trk", "x-lml/x-gps");
        types.put("trm", "application/x-msterminal");
        types.put("tsi", "audio/tsplayer");
        types.put("tsp", "application/dsptypes");
        types.put("tsv", "text/tab-separated-values");
        types.put("tsv", "text/tab-separated-values");
        types.put("ttf", "application/octet-stream");
        types.put("ttz", "application/t-time");
        types.put("txt", "text/plain");
        types.put("ult", "audio/x-mod");
        types.put("ustar", "application/x-ustar");
        types.put("uu", "application/x-uuencode");
        types.put("uue", "application/x-uuencode");
        types.put("vcd", "application/x-cdlink");
        types.put("vcf", "text/x-vcard");
        types.put("vdo", "video/vdo");
        types.put("vib", "audio/vib");
        types.put("viv", "video/vivo");
        types.put("vivo", "video/vivo");
        types.put("vmd", "application/vocaltec-media-desc");
        types.put("vmf", "application/vocaltec-media-file");
        types.put("vmi", "application/x-dreamcast-vms-info");
        types.put("vms", "application/x-dreamcast-vms");
        types.put("vox", "audio/voxware");
        types.put("vqe", "audio/x-twinvq-plugin");
        types.put("vqf", "audio/x-twinvq");
        types.put("vql", "audio/x-twinvq");
        types.put("vre", "x-world/x-vream");
        types.put("vrml", "x-world/x-vrml");
        types.put("vrt", "x-world/x-vrt");
        types.put("vrw", "x-world/x-vream");
        types.put("vts", "workbook/formulaone");
        types.put("wav", "audio/x-wav");
        types.put("wax", "audio/x-ms-wax");
        types.put("wbmp", "image/vnd.wap.wbmp");
        types.put("web", "application/vnd.xara");
        types.put("wi", "image/wavelet");
        types.put("wis", "application/x-InstallShield");
        types.put("wm", "video/x-ms-wm");
        types.put("wma", "audio/x-ms-wma");
        types.put("wmd", "application/x-ms-wmd");
        types.put("wmf", "application/x-msmetafile");
        types.put("wml", "text/vnd.wap.wml");
        types.put("wmlc", "application/vnd.wap.wmlc");
        types.put("wmls", "text/vnd.wap.wmlscript");
        types.put("wmlsc", "application/vnd.wap.wmlscriptc");
        types.put("wmlscript", "text/vnd.wap.wmlscript");
        types.put("wmv", "audio/x-ms-wmv");
        types.put("wmx", "video/x-ms-wmx");
        types.put("wmz", "application/x-ms-wmz");
        types.put("wpng", "image/x-up-wpng");
        types.put("wpt", "x-lml/x-gps");
        types.put("wri", "application/x-mswrite");
        types.put("wrl", "x-world/x-vrml");
        types.put("wrz", "x-world/x-vrml");
        types.put("ws", "text/vnd.wap.wmlscript");
        types.put("wsc", "application/vnd.wap.wmlscriptc");
        types.put("wv", "video/wavelet");
        types.put("wvx", "video/x-ms-wvx");
        types.put("wxl", "application/x-wxl");
        types.put("x-gzip", "application/x-gzip");
        types.put("xar", "application/vnd.xara");
        types.put("xbm", "image/x-xbitmap");
        types.put("xdm", "application/x-xdma");
        types.put("xdma", "application/x-xdma");
        types.put("xdw", "application/vnd.fujixerox.docuworks");
        types.put("xht", "application/xhtml+xml");
        types.put("xhtm", "application/xhtml+xml");
        types.put("xhtml", "application/xhtml+xml");
        types.put("xla", "application/vnd.ms-excel");
        types.put("xlc", "application/vnd.ms-excel");
        types.put("xll", "application/x-excel");
        types.put("xlm", "application/vnd.ms-excel");
        types.put("xls", "application/vnd.ms-excel");
        types.put("xlt", "application/vnd.ms-excel");
        types.put("xlw", "application/vnd.ms-excel");
        types.put("xm", "audio/x-mod");
        types.put("xml", "text/xml");
        types.put("xmz", "audio/x-mod");
        types.put("xpi", "application/x-xpinstall");
        types.put("xpm", "image/x-xpixmap");
        types.put("xsit", "text/xml");
        types.put("xsl", "text/xml");
        types.put("xul", "text/xul");
        types.put("xwd", "image/x-xwindowdump");
        types.put("xyz", "chemical/x-pdb");
        types.put("yz1", "application/x-yz1");
        types.put("z", "application/x-compress");
        types.put("zac", "application/x-zaurus-zac");
        types.put("zip", "application/zip");
    }
}
